//
// Created by xili on 2024/10/10 18:54.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int minimumLength(string s) {
        int n = s.size();
        int left = 0, right = n - 1;
        while (left < right) {
            if (s[left] == s[right]) {
                char currentChar = s[left];
                // 移动左指针跳过重复的字符
                while (left <= right && s[left] == currentChar) {
                    left++;
                }
                // 移动右指针跳过重复的字符
                while (left <= right && s[right] == currentChar) {
                    right--;
                }
            } else {
                break; // 字符不匹配，退出循环
            }
        }
        // 返回剩余的长度
        return right - left + 1;
    }
};